<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;


/**
 * @property int $id
 * @property int $article_id
 * @property int $user_id
 * @property int $reply_user_id
 * @property int $parent_id
 * @property string $content
 * @property int $like_count
 * @property int $is_stick
 * @property string $ip
 * @property string $browser
 * @property string $system
 * @property string $ip_source
 * @property string $create_time
 */
class Comment extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'comment';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['article_id', 'user_id', 'reply_user_id', 'parent_id', 'content', 'like_count', 'is_stick', 'ip', 'browser', 'system', 'ip_source', 'create_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'article_id' => 'integer', 'user_id' => 'integer', 'reply_user_id' => 'integer', 'parent_id' => 'integer', 'like_count' => 'integer', 'is_stick' => 'integer'];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
    public function replyUser()
    {
        return $this->belongsTo(User::class, 'reply_user_id', 'id');
    }

    public function article()
    {
        return $this->belongsTo(Article::class, 'article_id', 'id');
    }

    public function getCreateTimeAttribute()
    {
        return $this->attributes['create_time'];
    }
    public function getUpdateTimeAttribute()
    {
        return $this->attributes['update_time'];
    }
}
